import { api } from '../api';
import { User } from '@/typings/user';

export type UserLoginParams = {
  email: string;
  password: string;
}

/**
 * 用户登录
*/
export const userLoginApi = async (params: UserLoginParams) => {
  return api<User.TokenResult>('/login', {
    skipToken: true,
    variables: {
      type: 'PASSWORD',
      account: params.email,
      pin_code: params.password
    }
  });
}

/**
 * 获取用户信息
*/
type FetchUserParams = {
  userId?: string;
  token?: string;
}

export const fetchUserApi = (params?: FetchUserParams) => {
  const variables: Record<string, any> = {
    filter: { id: '67bc2f291880e0080671a0c3' }
  };
  return api<User.UserInfo>('/account/fetch', {
    variables: variables,
    token: params?.token
  });
}

/**
 * 刷新 token
*/
export const refreshTokenApi = (token: string) => {
  return api<User.TokenResult>('/refresh-token', {
    skipToken: true,
    variables: { token }
  });
}
